#include "weaponLightning.h"
#include "../world/spell.h"
#include "../core/scene.h"
#include "../core/actor.h"
#include "../screen/hud_skill.h"
weaponLightning *weaponLightning::createWLightning(actor *parent, float cooldown, float manacost)
{
    auto wLightning = new weaponLightning();
    wLightning->init();
    wLightning->setParent(parent);
    wLightning->setCoolDown(cooldown);
    wLightning->setManaCost(manacost);
    parent->addChild(wLightning);
    return wLightning;
}

void weaponLightning::init()
{
    weapon::init();
    auto sceneMain = game_.getCurrentScene();
    skill = hud_skill::createHubSkill(sceneMain,"assets/UI/Electric-Icon.png","hud_skill",
        glm::vec2(game_.getScreenSize().x - 300,30),0.14f);
}

bool weaponLightning::handleEvents(SDL_Event &event)
{
    if(event.type == SDL_EVENT_MOUSE_BUTTON_DOWN && event.button.button == SDL_BUTTON_LEFT)
    {
        if(canAttack()){
            auto pos = game_.getMousePosition()+game_.getCurrentScene()->getCameraPosition();
            auto spell = spell::createSpell(nullptr,"assets/effect/Thunderstrike w blur.png",pos,40,u8"闪电",3.0f);
            attack(pos,spell);
            game_.playSound("assets/sound/big-thunder.mp3");
            
            return true;
        }
    }
    return false;
}

void weaponLightning::update(float dt)
{
    weapon::update(dt);
    if(skill)skill->setPrecent(cool_down_timer_/cool_down_);
}
